package com.javasea.web.mapstruct.mapper;

import com.javasea.web.mapstruct.entity.Order;
import com.javasea.web.mapstruct.entity.User;
import com.javasea.web.mapstruct.entity.UserVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

@Mapper
public interface UserMapper {
    UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);

    @Mapping(source = "tel",target = "telNumber")
    @Mapping(source = "birthday",target = "birthday",dateFormat = "yyyy-MM-dd")
    UserVo convertToVo(User user);

    @Mapping(source = "tel", target = "telNumber")
    @Mapping(source = "birthday", target = "birthday", dateFormat = "yyyy-MM-dd")
    List<UserVo> toVoList(List<User> list);


    /** 属性合并 */
    @Mapping(source = "user.tel",target = "telNumber")
    @Mapping(source = "user.birthday",target = "birthday",dateFormat = "yyyy-MM-dd")
    @Mapping(source = "user.id",target = "id")
    @Mapping(source = "order.orderNo", target = "orderNo")
    @Mapping(source = "order.receiverAddress", target = "receiverAddress")
    UserOrderVo toUserOrderVo(User user, Order order);
}
